#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int size = 0;
    cin >> size;
    vector<int> array(size);
    for (int i = 0; i < array.size(); i++)
    {
        cin >> array[i];
    }
    int sum = array[0], maxNum = array[0];
    for (int i = 1; i < array.size(); i++)
    {
        sum = sum + array[i] > array[i] ? sum + array[i] : array[i];
        maxNum = sum > maxNum ? sum : maxNum;
    }
    cout << maxNum;
    return 0;
}